package com.tnt.googlekaptcha;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author zhuangxl
 * @description google kaptcha 图片验证码配置
 * @since 2021-03-04 13:52
 */
@Configuration
public class KaptchaConfig {

    @Bean
    public Producer producer(){

        Properties properties = new Properties();

        //图片边框
        properties.put("kaptcha.border", "no");

        //图片字符长度
        properties.put("kaptcha.textproducer.char.length","4");

        // 图片长宽
        properties.put("kaptcha.image.height","50");
        properties.put("kaptcha.image.width","100");

        //图片显示样式
        properties.put("kaptcha.obscurificator.impl","com.google.code.kaptcha.impl.WaterRipple");

        //字体颜色
        properties.put("kaptcha.textproducer.font.color","blue");

        //字体大小
        properties.put("kaptcha.textproducer.font.size","40");

        //干扰 可选参数com.google.code.kaptcha.impl.NoNoise、com.google.code.kaptcha.impl.DefaultNoise;
        properties.put("kaptcha.noise.impl","com.google.code.kaptcha.impl.DefaultNoise");
        properties.put("kaptcha.noise.color", "255,96,0");

        //排除b、g、i、l、o、q、s、z,1、0、9等比较难判断的字母和数字
        properties.put("kaptcha.textproducer.char.string","acdefhkmnprtwxy2345678");

        Config config = new Config(properties);

        return config.getProducerImpl();
    }
}
